package com.zhang.springbootdemo.controller;

import com.zhang.springbootdemo.pojo.Employee;
import com.zhang.springbootdemo.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class EmployeeController {
    @Autowired
    private EmployeeService employeeService;

    /**
     * 增
     * @param emp
     * @return
     */
    @RequestMapping("/add")
    public boolean addEmp(Employee emp){
        return employeeService.addEmp(emp);
    }

    /**
     * 删
     * @param eId
     * @return
     */
    @RequestMapping("/del")
    @ResponseBody
    public boolean delEmpByid(Integer eId){

        return employeeService.delEmpByid(eId);

    }
    /**
     *改
     * @param emp
     * @return
     */
    @RequestMapping("/edit")
    @ResponseBody
    public boolean editEmp(Employee emp){
        return employeeService.editEmp(emp);
    }

    /**
     * 查询员工数据
     * @return
     */

    @RequestMapping("/sel")
    public String selEmp(Model model){

        List<Employee> employees = employeeService.selEmp();
        model.addAttribute("emps",employees);
        return "employee";
    }
    @PostMapping("/sels")
    public List selEmps( Employee employee){
        return employeeService.selEmps(employee);
    }

}
